package com.hassean.we.admin.controller;
import java.util.Map;
import java.util.Date;



import com.hassean.we.admin.service.IpphoneUserService;
import com.hassean.we.common.constant.CommonConstant;
import com.hassean.we.common.util.Query;
import com.hassean.we.common.util.R;
import com.hassean.we.model.entity.IpphoneRecharge;
import com.hassean.we.model.entity.IpphoneUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.hassean.we.admin.service.IpphoneRechargeService;
import com.hassean.we.common.web.BaseController;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author yajun
 * @since 2019-07-01
 */
@RestController
@RequestMapping("/ipphoneRecharge")
public class IpphoneRechargeController extends BaseController {
    @Autowired private IpphoneRechargeService ipphoneRechargeService;
    @Autowired private IpphoneUserService ipphoneUserService;
    /**
    * 通过ID查询
    *
    * @param params
    * @return IpphoneRecharge
    */
    @RequestMapping("/{id}")
    public R<IpphoneRecharge> get(@RequestBody Map<String, Object> params) {
        Integer id = Integer.parseInt(params.get("id").toString());
        return new R<>(ipphoneRechargeService.selectById(id));
    }


    /**
    * 分页查询信息
    *
    * @param params 分页对象
    * @return 分页对象
    */
    @RequestMapping("/page")
    public Page page(@RequestBody Map<String, Object> params) {
        params.put(CommonConstant.DEL_FLAG, CommonConstant.STATUS_NORMAL);
        return ipphoneRechargeService.selectPage(new Query<>(params), new EntityWrapper<>());
    }

    /**
     * 添加
     * @param  ipphoneRecharge  实体
     * @return success/false
     */
    @RequestMapping("/add")
    public R<Boolean> add(@RequestBody IpphoneRecharge ipphoneRecharge) {
        //这里还要把数据推给他们
        return new R<>(ipphoneRechargeService.insert(ipphoneRecharge));
    }

    /**
     * 删除
     * @param params
     * @return success/false
     */
    @RequestMapping("/delete")
    public R<Boolean> delete(@RequestBody Map<String, Object> params) {
        Long id = Long.parseLong(params.get("id").toString());
        IpphoneRecharge ipphoneRecharge = new IpphoneRecharge();
        ipphoneRecharge.setRechargeId(id);
        ipphoneRecharge.setUpdateTime(new Date());
        ipphoneRecharge.setDelFlag(CommonConstant.STATUS_DEL);
        return new R<>(ipphoneRechargeService.updateById(ipphoneRecharge));
    }

    /**
     * 编辑
     * @param  ipphoneRecharge  实体
     * @return success/false
     */
    @RequestMapping
    public R<Boolean> edit(@RequestBody IpphoneRecharge ipphoneRecharge) {
        ipphoneRecharge.setUpdateTime(new Date());
        return new R<>(ipphoneRechargeService.updateById(ipphoneRecharge));
    }
    /**
     * 支付接口
     */
    public void palyfor(){
        System.out.println("我是支付接口");
    }

    /**
     * 充值回退
     */
    @RequestMapping("/rechargeBackspace")
    public  R<Boolean> RechargeBackspace(@RequestBody Map<String, Object> params){

       String fee = params.get("fee").toString();
       Long userId = Long.parseLong(params.get("fee").toString().toString());
        //在总金额中减去回退的金额
        IpphoneUser ipphoneUser =  ipphoneUserService.selectById(userId);
        if (ipphoneUser!=null){
            //通过他们数据库中获取用户总额，
        }
        System.out.println("我是充值回退接口");
        return new R<>(false);
    }
}
